﻿@page "/importexportinfos"
@using Compass.Wasm.Shared.Logistics
@using Compass.Wasm.Client.Services.Logistics
@inject IImportExportInfoService ImportExportInfoService;


<PageTitle>进出口货物申报要素查询</PageTitle>
<!--sticky固定位置，top: 3.5rem-->
<div style="position: sticky; top: 3.5rem; z-index: 1;background-color:White">
    <div class="row position-relative">
        <div class="col input-group mb-2">
            <span class="input-group-text">搜索</span>
            <input class="form-control" placeholder="Search"
                   @bind-value="@_search" @oninput="@Search" />
        </div>
        <div class="col ms-3" style="max-width: 70px">

        </div>
        @*todo:控制权限*@
        <CompAddButton Roles="admin,log" Url="importexportinfo/add" />
    </div>
</div>

<table class="table table-hover table-striped" style="table-layout: fixed; word-break: break-all;">
    <!--sticky固定位置，top: 6rem-->
    <thead style="position: sticky; top: 6rem; z-index: 1; background-color: White">
        <tr>
            <th style="width: 160px">料号</th>
            <th style="text-align: center;width: 90px">类型</th>
            <th style="text-align: center;width: 110px">BU</th>
            <th >品名</th>
            <th style="width: 120px">
                
                <a href="http://old.hscode.net/IntegrateQueries/QueryYS" target="_blank">
                    <span class="oi oi-magnifying-glass"></span>
                </a>
                <span class="ms-2">HS编码</span>
            </th>
            <th >HS描述</th>
            <th style="text-align: center;width: 130px">产地</th>
            <th style="text-align: center;width: 90px">申报要素</th>
        </tr>
    </thead>
    <tbody>
        @if (_filterImportExportInfoDtos.Count == 0)
        {
            <p>...</p>
        }
        else
        {
            @foreach (var importExportInfo in _filterImportExportInfoDtos)
            {
                <ImportExportInfoRow ImportExportInfoDto="importExportInfo" />
            }
        }
    </tbody>
</table>



@code {
    private string _search = string.Empty;

    private List<ImportExportInfoDto> _importExportInfoDtos = new();
    private List<ImportExportInfoDto> _filterImportExportInfoDtos = new();

    protected override async Task OnParametersSetAsync()
    {
        var result = await ImportExportInfoService.GetAllAsync();
        _importExportInfoDtos = result.Result;
        Search(new ChangeEventArgs { Value = "" });
    }
    private void Search(ChangeEventArgs e)
    {
        _search=e.Value!.ToString()!;
        _filterImportExportInfoDtos.Clear();
        _filterImportExportInfoDtos = _importExportInfoDtos.Where(
            x => 
                  string.IsNullOrEmpty(_search)||
                  x.MtlNumber.Contains(_search, StringComparison.OrdinalIgnoreCase)||
                   x.Name.Contains(_search, StringComparison.OrdinalIgnoreCase)||
                  x.HsCode.Contains(_search, StringComparison.OrdinalIgnoreCase)||
                  x.HsDescription.Contains(_search, StringComparison.OrdinalIgnoreCase)||x.HsCode.Contains(_search, StringComparison.OrdinalIgnoreCase)||
                  x.PlaceOfOrigin.Contains(_search, StringComparison.OrdinalIgnoreCase)||
                  x.DeclarationElements.Contains(_search, StringComparison.OrdinalIgnoreCase)||
                  (x.PoNumbers!=null &&
                   x.PoNumbers.Contains(_search, StringComparison.OrdinalIgnoreCase))||
                   (x.NavDescription!=null &&
                   x.NavDescription.Contains(_search, StringComparison.OrdinalIgnoreCase)))
            .ToList();
    }
}
